using Microsoft.Extensions.DependencyInjection.Extensions;
using TK.Common.Http;

namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// ServiceCollectionExtensions
    /// </summary>
    public static class TKServiceCollectionExtensions
    {
        /// <summary>
        /// 注册httpclinet请求服务
        /// </summary>
        public static IHttpClientBuilder AddTKHttpClient(this IServiceCollection services, string clientName = "")
        {
            services.TryAddTransient<HttpClientTraceDelegatingHandler>();
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            clientName = string.IsNullOrWhiteSpace(clientName) ? string.Empty : clientName;
            return services.AddHttpClient(clientName).AddHttpMessageHandler<HttpClientTraceDelegatingHandler>();
        }
    }
}
